package com.water.camera.kt

import androidx.lifecycle.viewModelScope
import com.snap.base.ktx.isLogin
import com.snap.base.ktx.requestUserInfo
import com.snap.base.util.BaseUtil
import com.snap.common.main.BaseVM
import com.snap.login.ktx.payWithWX
import com.snap.login.ktx.startLoginAct
import com.snap.util.toast
import kotlinx.coroutines.launch

class BuyVM : BaseVM() {

    lateinit var back: () -> Unit

    fun clickBuy(priceId: Int) {
        if (!BaseUtil.isLogin()) {
            BaseUtil.startLoginAct(false, firstColor = "#FFF4E6", goneQQ = true)
            return
        }
        viewModelScope.launch {
            BaseUtil.payWithWX(priceId, success = {
                toast("支付成功")
                ShareVM.isOutWithBuy = false
                viewModelScope.launch {
                    BaseUtil.requestUserInfo()
                    back()
                }
            }, failed = {
                toast("支付失败")
            })
        }

    }
}